package com.iuie.ns.system.service.menu.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.iuie.ns.frame.persistence.dao.IGenericDao;
import com.iuie.ns.frame.service.impl.BaseServiceImpl;
import com.iuie.ns.frame.utils.BeanUtils;
import com.iuie.ns.frame.utils.ListUtils;
import com.iuie.ns.frame.utils.beans.UserOperateVO;
import com.iuie.ns.system.dao.menu.ISysMenuDao;
import com.iuie.ns.system.mapper.menu.SysMenuMapper;
import com.iuie.ns.system.service.menu.ISysMenuService;
import com.iuie.ns.system.vo.resource.SysResourceVO;

/**
 * @desc TODO
 * @createTime 2017年6月25日 下午1:04:28
 * @author iuie
 */
@Service("menuService")
public class SysMenuServiceImpl extends BaseServiceImpl<SysResourceVO> implements ISysMenuService {

    @Resource
    private ISysMenuDao menuDao;
    
    @Resource
    private SysMenuMapper menuMapper;

    @Override
    protected IGenericDao<SysResourceVO, Serializable> getGenericDao() {
        return menuDao;
    }
    
    @Override
    public List<SysResourceVO> findAll(SysResourceVO params) {
    	return menuMapper.findAll(params);
    }

    @Override
    public void save(UserOperateVO oper) throws Exception {
        List<SysResourceVO> newRecords = BeanUtils.mapsToObjects(oper.getNewRecords(), SysResourceVO.class);
        List<SysResourceVO> updateRecords = BeanUtils.mapsToObjects(oper.getUpdateRecords(), SysResourceVO.class);
        List<SysResourceVO> deleteRecords = BeanUtils.mapsToObjects(oper.getDeleteRecords(), SysResourceVO.class);
        if (ListUtils.isNotEmpty(newRecords)) {
            menuMapper.batchAdd(newRecords);
        }
        if (ListUtils.isNotEmpty(updateRecords)) {
            menuMapper.batchUpdate(updateRecords);
        }
        if (ListUtils.isNotEmpty(deleteRecords)) {
            menuMapper.batchDelete(deleteRecords);
        }
    }

	@Override
	public void batchUpdate(List<SysResourceVO> updateRecords) throws Exception {
		if (ListUtils.isNotEmpty(updateRecords)) {
			menuMapper.batchUpdate(updateRecords);
		}
	}

	@Override
	public void batchAdd(List<SysResourceVO> newRecords) throws Exception {
		if (ListUtils.isNotEmpty(newRecords)) {
			menuMapper.batchAdd(newRecords);
		}
	}

	@Override
	public void batchDelete(List<SysResourceVO> deleteRecords) throws Exception {
		if (ListUtils.isNotEmpty(deleteRecords)) {
			menuMapper.batchDelete(deleteRecords);
		}
	}
    
}
